<?php

namespace app\bank_api\controller;

use app\common\library\Auth;
use fast\Random;


/**
 * 员工接口
 */
class Staff extends Base
{
    protected $noNeedRight = '*';


    public function reset_password()
    {
        $this->onlyPost();
        $old_password  = $this->request->post('old_password');
        $new_password  = $this->request->post('new_password');

        $staff = \app\common\model\Staff::where('id',$this->staffinfo['id'])->find();
        if ($staff->password != md5(md5($old_password) . $staff->salt)) {
            $this->error('请输入正确的原密码');
        }

        if($old_password == $new_password) $this->error('旧密码不能与新密码相同');
        if(strlen($new_password) < 6)    $this->error('密码不能低于6位');

        $staff->salt        = Random::alnum();
        $staff->password    = Auth::instance()->getEncryptPassword($new_password,$staff->salt);

        $res = $staff->save();

        $res ? $this->success('重置密码成功') : $this->error('重置密码失败');
    }




}
